<template>
	<view class="searchindex" :style="skin">
		<jnavbar :title="'搜索'"></jnavbar>
		<view class="uni-flex-row search_div">
			<view class="uni-flex-row input_div">
				<text class="iconfont el-sc-search"></text>
				<input confirm-type="search" @confirm="search" v-model="keywords" type="text" @click="show = true" placeholder="搜索商品" />
			</view>
			<text class="search_btn" @click="search">搜索</text>
		</view>
		<view>
			<view class="list-box">
				<view class="list-title">
					<text class="title-content">搜索历史</text>
					<u-icon name="trash" @click="clear"></u-icon>
				</view>
				<view class="list-item" v-if="searchList.length >0">
					<u-tag :text="item.name" type="info" shape="circle" border-color="#fff" v-for="(item,i) in searchList" :key='i' @click="onClickTag(item.name)" />
					<!-- <view class="list-item-more">
						<text class="iconfont el-sc-xiangji1"></text>
					</view> -->
				</view>
				<view class="no-list" v-else>
					<text>没有搜索历史</text>
				</view>
			</view>
			<view class="list-box">
				<view class="list-title">
					<text class="title-content">搜索热点</text>
				</view>
				<view class="list-item">
					<u-tag :text="item" type="info" shape="circle" border-color="#fff" v-for="(item, index) in hotspotList" :key="index"
					 @click="onClickTag(item)" />
					<!-- <view class="list-item-more" v-if="hotspotList.length>9">
						<text class="iconfont el-sc-xiangji1"></text>
					</view> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		onShareAppMessage() {
			return this.wxShare();
		},
		data() {
			return {
				keywords: '',
				show: false,
				hotspotList: [],
				value: ''
			};
		},
		async onLoad() {
			await this.$getWx
			this.getSearchList()
		},
		computed: {
			...mapState(['searchList','skin'])
		},
		methods: {
			search() {
				undefined == this || !this.keywords || (() => {
					this.$store.dispatch('set_search', {
						name: this.keywords
					})

				})();
				this.Jumpurl({
					link: './list?name=' + this.keywords,
					login_type: 1,
					type: 1
				}, "redirect")
			},
			getSearchList() {
				this.$http('/search/keyword', 'GET').then(res => {
					this.hotspotList = res.data.msg
				})
			},
			onClickTag(item) {
				this.keywords = item
				this.search()
			},
			clear() {
				this.$store.dispatch('clear_search')
				uni.showToast({
					title: "清空完成"
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.searchindex {
		background: #fff;
		height: 100vh;

		.search_div {
			padding: 16rpx 24rpx;
			align-items: center;

			.input_div {
				flex: 1;
				position: relative;
				border-radius: 30rpx;
				border: solid 1px var(--main-color);
				overflow: hidden;
				display: flex;

				input {
					width: 100%;
					height: 60rpx;
					line-height: 60rpx;
					font-size: 24rpx;
					color: #212121;
					border-radius: 6px;
					padding-left: 70rpx;
					overflow: hidden;
				}

				text {
					position: absolute;
					left: 12rpx;
					top: 12rpx;
				}

				/deep/.uni-input-wrapper {
					height: 60rpx;
					min-height: 60rpx;
				}
			}

			.search_btn {
				padding: 20rpx 30rpx;
				color: #fff;
				font-size: 24rpx;
				line-height: 16rpx;
				background: var(--main-color);
				border-radius: 30rpx;
				margin-left: 20rpx;
			}
		}

		.list-box {
			display: flex;
			flex-direction: column;

			.list-title {
				padding: 0 24rpx;
				display: flex;
				justify-content: space-between;

				.title-content {
					font-size: 28rpx;
					font-weight: bold;
				}
			}

			.no-list {
				width: 100%;
				height: 200rpx;
				line-height: 200rpx;
				text-align: center;
				font-size: 24rpx;
			}

			.list-item {
				padding: 0 24rpx;
				margin: 25rpx 0;
				font-size: 24rpx;
				display: flex;
				flex-wrap: wrap;

				.u-tag {
					margin: 15rpx 10rpx;
				}

				.list-item-more {
					border-radius: 50%;
					width: 52rpx;
					height: 52rpx;
					color: #909399;
					margin: 15rpx 10rpx;
					background: #f4f4f5;
					text-align: center;
					line-height: 52rpx;
				}
			}
		}

		.search-list {
			width: 100%;
			display: flex;
			flex-direction: column;
			background: #fff;

			.list-item {
				padding: 10px 20px;
				border-bottom: 1px solid #e8e8e8;
				font-size: 32rpx;
			}

			.list-item:last-child {
				padding: 10px 20px;
				border-bottom: none;
			}
		}
	}
</style>
